﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EasySite.Services;
using NUnit.Framework;

namespace EasySite.Tests.ServiceTests
{

    public class UserServiceTests : DbUnitTestBase
    {
        [Test]
        public void Login_should_succeed()
        {
            var service = base.GetService<IUserService>();
            var success = service.Login("leo_2010", "111111", "127.0.0.1");
            Assert.IsTrue(success);
        }

        [Test]
        public void Login_should_fail_with_invalid_password()
        {
            var service = base.GetService<IUserService>();
            var success = service.Login("leo_2010", "password", "127.0.0.1");
            Assert.IsTrue(success == false);
        }

        [Test]
        public void Login_should_fail_with_invalid_user()
        {
            var service = base.GetService<IUserService>();
            Assert.IsTrue(!service.Login("deletedUser", "111111", "127.0.0.1"));
            Assert.IsTrue(!service.Login("inactiveUser", "111111", "127.0.0.1"));
        }

        [Test]
        public void Should_return_roles()
        {
            var service = base.GetService<IUserService>();
            var roles = service.GetRoles("leo_2010");
            Assert.IsTrue(roles.Length == 1);
        }

        [Test]
        public void Shouldnt_return_null_roles()
        {
            var service = base.GetService<IUserService>();
            var roles = service.GetRoles("leo_20120106");
            Assert.IsTrue(roles != null);
        }
    }
}
